package com.kayt.cyberBar.cuser.business.server.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kayt.cyberBar.cuser.business.dao.ICyberBaseTaskAttachDao;
import com.kayt.cyberBar.cuser.business.entity.po.BCyberBaseTaskAttach;
import com.kayt.cyberBar.cuser.business.entity.vo.CyberBaseTaskAttachVO;
import com.kayt.cyberBar.cuser.business.server.ICyberBaseTaskAttachServer;

@Service("iCyberBaseTaskAttachServer")
public class CyberBaseTaskAttachServerImpl implements ICyberBaseTaskAttachServer {
	private static Logger logger = LoggerFactory.getLogger(CyberBaseTaskAttachServerImpl.class);
	
	@Autowired
	private ICyberBaseTaskAttachDao iCyberBaseTaskAttachDao;

	@Override
	public BCyberBaseTaskAttach get_attach_by_code(String reportCode) {
		if (reportCode != null) {
			try {
				BCyberBaseTaskAttach item = this.iCyberBaseTaskAttachDao.getAttachByCode(reportCode);
				return item;
			} catch (SQLException e) {
				logger.error("get_attach_by_code with a SQLException", e);
			}
		}
		return null;
	}
	
	@Override
	public CyberBaseTaskAttachVO assemble_vo(BCyberBaseTaskAttach item) {
		if (item != null) {
			CyberBaseTaskAttachVO vo = new CyberBaseTaskAttachVO();
			vo.setCode(item.getCode());
			vo.setCreateTime(item.getCode());
			String id = item.getId() == null ? null : item.getId().toString();
			vo.setId(id);
			vo.setAttachUrl(item.getAttachUrl());
			vo.setReportCode(item.getReportCode());
			vo.setSequnce(item.getSequnce());
			vo.setUpdateTime(item.getUpdateTime());
			return vo;
		}
		return null;
	}
	
	@Override
	public List<CyberBaseTaskAttachVO> assemble_vo_list (List<BCyberBaseTaskAttach> itemList) {
		List<CyberBaseTaskAttachVO> voList = new ArrayList<>();
		if (itemList != null && !itemList.isEmpty()) {
			for (BCyberBaseTaskAttach item : itemList) {
				CyberBaseTaskAttachVO vo = this.assemble_vo(item);
				voList.add(vo);
			}
		}
		return voList;
	}
}
